package search.binarysearch;

/**
 * @author XY
 * @version 1.0
 * @date 2022/3/1 9:23
 * @Description
 */
public class Leet35 {
    public int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length-1;
        int mid = -1;
        while(l<=r){
            mid = (l+r)/2;
            if(nums[mid]==target){
                return mid;
            }
            if(nums[mid]<target){
                l = mid+1;
            }
            if(nums[mid]>target){
                r = mid-1;
            }
        }
        return l;
    }
}
